$(function () {
    getNewsData(1,0);
});
var newsType=0;
var pageNum = 1;
function getNewsData(page,news_type) {
    if (page==null || page=='')
        page = pageNum;
    if (news_type==null||news_type=='')
        news_type = newsType;
    let data = myAjax('/news', 'post', {"news_type":news_type,"page":page}, 'json');
    sessionStorage.setItem("newsData",JSON.stringify(data));
    console.log(data);
    $(".news_type").html("");
    $.each(data.newsTypes,function (i,newstype) {
        $(".news_type").append("<div onclick='getNewsData(1,"+newstype.id+")'>"+ newstype.name +"</div>");
    });
    $(".news_list").html("");
    $.each(data.news,function (i,news) {
        $(".news_list").append("<div><a class='header'> <div class='type' onclick='getNewsData(1,"+news.newsType.id+")'>["+news.newsType.name+"]</div><div class='title' onclick='redirectNewsDetails("+i+")'>"+ news.title +"</div></a><div class='date'>"+news.create_time+"</div></div>");
    });
};
function redirectNewsDetails(i) {
    sessionStorage.setItem("newsi",i);
    window.location.href = "/html/front/newsdetails.html";
}